//-----------------------------------------------------
// application.h
//-----------------------------------------------------

/**
 * comment here
 */

#pragma once

namespace application {

	class CApplication {
	public:
		// Class constructor
		CApplication();

		// Class destructor
		virtual ~CApplication() {}

		/**
			Returns the application instance. The Class
			implements singleton through the constructor
		*/
		static CApplication* getApp();

		/**
			Initialize the application.
			@return false if the inicialization failed.
		*/
		virtual bool init();

		/**
			Ends the application freeing resources
		*/
		void end();

		/**
			Function to execute the application
		*/
		virtual void run();

		/**
			This function is called when someone outside the
			application (usually an state), wants to end the application
			This function is meant to be called while the method run is running.
		*/
		void requestTermination() {
			_termination = true;
		}

		/**
			Function to ask if someone has requested the application to end.
			@return Returns wether the application will end within the current
			loop execution.
		*/
		bool terminationRequested() {
			return _termination;
		}

	protected:

		/**
			Function to step the main loop of the application.
		*/
		virtual void step();

		/**
			Single instance of the application.
		*/
		static CApplication* _instance;

		/**
			Tells if the application has been initialized
		*/
		bool _initialized;

		/**
			Tells if the application will end with the current step of the main loop.
		*/
		bool _termination;

	}; // class CApplication

	inline CApplication* CApplication::getApp() {
		return _instance;
	}

} // namespace application
